package com.hzw.net.page.status

import android.content.Context
import android.view.View
import android.view.ViewStub
import com.hzw.core.view.gone
import com.hzw.net.R
import com.hzw.net.weiget.LoadingView

class LoadingPageStatus(override val context: Context) : ILoadingStatus {

    override val viewStub: ViewStub = ViewStub(context, R.layout.loading_layout).also {
        it.gone()
        it.setOnClickListener(null)
    }

    private var view: View? = null
    private var loadingView: LoadingView? = null

    override fun startLoading() {
        loadingView?.start()
    }

    override fun endLoading() {
        loadingView?.stop()
    }

    override fun inflate(): View {
        if (view == null) {
            view = viewStub.inflate()
            if (view == null) {
                throw IllegalArgumentException("StateViewStub ==> viewStub.inflate() 加载失败")
            }
        }
        loadingView = view!!.findViewById(R.id.loadingView)
        return view!!
    }

    override fun release() {

    }
}